<?php
	class CustomerInvoiceController extends Controller{
		private $result = array("actionStatus"=>0,"actionMessage"=>"","model"=>array(),"actionError"=>array());	
		public $mainMenu = "Finance";
		public $subMenu = "";
		public $title = "";
		public $loginUser = ""; 
		public function init() {
			$this->loginUser = LoginUser::getUser();
		}
		
		public function actionIndex(){
			$data=array();
			$this->layout ="//layouts/ly_blank";
			$this->render('index',$data);
		}
		
		public function actionInvoiceForm(){
			$op = Yii::app()->request->getParam("op","add");			
			$arrCustomer = MCustomer::model()->findAll("is_active = 1");
			
			$acCustomer = array();
			foreach ($arrCustomer as $customer){
				$tmp = array();
				$tmp["label"] = $customer->name;
				$tmp["value"] = $customer->name;
				$tmp["id"] = $customer->id;
				$acCustomer[] = $tmp;
			}
			$id=0;
			$invoice_no = "";
			$invoice_date = date("d-M-Y");
			$customer_id = "";
			$customer_name = "";
			$notes="";
			$ttl_invoice= 0;
			$ttl_disc= 0;
			$payment_type="CASH";
			$dInv = array();
			$customer_transaction_type_id ="";
			$autoId = 0;
			
			$arrCustomerTransactionType = MCustomerTransactionType::model()->findAll("is_active = 1");
			if ($op == "add"){				
				$customer_id = 1; // Customer Umum;
				$customer  = MCustomer::model()->findByPK(1);
				$customer_name = $customer->name;
				$invoice_no = AutoNumber::getNewCustomerInvoiceNo();				
			}else if ($op == "edit"){
				$id = Yii::app()->request->getParam("id","");				
				$hInv = MCustomerHinvoice::model()->findByPK($id);
				if ($hInv == null){
					echo Yii::t("label","Invoice tidak di temukan");
					exit;
				}
				
				$invoice_no = $hInv->invoice_no;				
				$invoice_date = $hInv->invoice_date;
				$invoice_date =  date_format(date_create_from_format( "Y-m-d", $invoice_date),"d-M-Y");
				$customer_transaction_type_id = $hInv->customer_transaction_type_id;
				$customer_id = $hInv->customer_id;
				$customer_name = $hInv->customer->name;
				$notes=$hInv->notes;
				$ttl_invoice= $hInv->ttl_invoice;
				$ttl_disc= $hInv->ttl_disc;
				$payment_type="CASH";				
				$arrDInv = MCustomerDinvoice::model()->findAll("invoice_id =:invId",array(":invId"=>$id));		
				foreach($arrDInv as $rw){
					$autoId += 1;
					$tmp=array();
					$tmp["id"] = $autoId;
					$tmp["customer_item_id"] = $rw->customer_item_id;
					$tmp["customer_item_desc"] = $rw->customerItem->item_desc;
					$tmp["notes"]= $rw->notes;
					$tmp["total"]= $rw->total;
					$tmp["qty"]=$rw->qty;
					$tmp["disc"] = $rw->disc;
					$tmp["total_after_disc"]= ($rw->total * $rw->qty)- $rw->disc;
					$tmp["status"]="existing";
					$dInv[] =$tmp; 					
				}
				
			}
			$data["op"]= $op;
			$data["id"]=$id;
			$data["acCustomer"]=CJSON::encode($acCustomer);
			$data["invoice_no"]= $invoice_no;
			$data["invoice_date"]= $invoice_date;
			$data["customer_transaction_type_id"]= $customer_transaction_type_id;
			$data["customer_id"]= $customer_id;
			$data["customer_name"]= $customer_name;
			$data["notes"]= $notes;
			$data["ttl_invoice"]= $ttl_invoice;
			$data["ttl_disc"]= $ttl_disc;
			$data["payment_type"]= $payment_type;	
			$dInv = json_encode($dInv);
			$data["dInv"]= $dInv;
			$data["autoId"]= $autoId;
			$data["arrCustomerTransactionType"] = $arrCustomerTransactionType;			
			$this->layout ="//layouts/ly_blank";
			$this->render('invForm',$data);
		}
		
		public function actionCnForm(){
			$errorMessage = array();
			$data = array();
			$id = Yii::app()->request->getParam("id",0);
			$op = Yii::app()->request->getParam("op","");
			
			if ($op != "delete"){
				$hInv = MCustomerHinvoice::model()->find("id = :id and is_active = 1",array(":id"=>$id));
				if ($hInv == null){
					$errorMessage = Yii::t("label","Data invoice tidak di temukan!");
					$this->pageError($errorMessage);
				}
			}
			
			if($op == "add"){
				//add
				$errorMessage = Yii::t("label","Data tidak dapat di simpan..!");
				$notes = Yii::app()->request->getParam("notes","");
				$cn_date = Yii::app()->request->getParam("cn_date",date("d-M-Y"));
				$cn_date = date_format(date_create_from_format( "d-M-Y", $cn_date),"Y-m-d");
				
				$cn_acc_id = Yii::app()->request->getParam("cn_acc_id",0);
				$cek = MCoa::model()->find("id =:id and is_active = 1",array(":id"=>$cn_acc_id));
				if ($cek == null){
					$errorMessage = Yii::t("label","Account ID credit note tidak di kenal !");
					$this->pageError($errorMessage,	$studentCN->getErrors());
				}
				
				$ttl_cn =  Yii::app()->request->getParam("ttl_cn",0);
				$ttl_cn = Utils::parseCurrency($ttl_cn);
				
				$conn = Yii::app()->db;
				$transaction = $conn->beginTransaction();
				try{
					//Create Jurnal
					$tmp = Jurnal::createHeader("Credit Note ". $hInv->invoice_no , $cn_date);
					$jurnalId = $tmp["id"];
				
					$customerCN = new MCustomerCreditNotes();
					$customerCN->cn_date = $cn_date;
					$customerCN->invoice_id = $id;
					$customerCN->cn_acc_id = $cn_acc_id;
					$customerCN->ttl_cn = $ttl_cn;
					$customerCN->notes = $notes;
					$customerCN->jurnal_id = $jurnalId;
					$customerCN->is_active = 1;
					$customerCN->input_datetime = date("Y-m-d H:i:s");
					$customerCN->user_id = $this->loginUser->id;
									
					if(!$customerCN->save()){
						throw new Exception(json_encode($customerCN->getErrors()));
					}
				
					//Update Invoice
					$hInv->ttl_cn = $hInv->ttl_cn + $ttl_cn;
					if (!$hInv->save()){
						throw new Exception(json_encode($hInv->getErrors()));
					}
					$tmp = Jurnal::createDetail($jurnalId, $cn_acc_id, "", "D", $ttl_cn);
					$tmp = Jurnal::createDetail($jurnalId, $hInv->piutang_acc_id, "", "C", $ttl_cn);
					
				}catch (Exception $e){
					$transaction->rollback();
					$this->pageError($errorMessage,	$e->getMessage());
				}
				
				$transaction->commit();
				echo "<script>window.top.location.href='index.php?r=keuangan/tu/customerInvoice/cnForm&id=$id'</script>";
								
			}else if($op == "delete"){
				//id di sini merupaka id dari student credit notes
				$errorMessage = Yii::t("dialog","Hapus data credit notes, gagal !");
				$successMessage = Yii::t("dialog","Data credit notes, telah di hapus !");
				$customerCN = MCustomerCreditNotes::model()->find("id = :id and is_active = 1",array(":id"=>$id));
				$conn = Yii::app()->db;
				$transaction = $conn->beginTransaction();
				try{
					$jurnalId = $customerCN->jurnal_id;
					//delete detail jurnal
					Jurnal::deleteDetailJurnal($jurnalId,$conn);				
					//update invoice
					$customerCN->invoice->ttl_cn = $customerCN->invoice->ttl_cn - $customerCN->ttl_cn;
					if (!$customerCN->invoice->save()){
						$transaction->rollback();
						$this->result["actionStatus"] =1;
						$this->result["actionMessage"] = $errorMessage;
						$this->result["actionError"] = $studentCN->invoice->getErrors();
						$this->returnJSON($this->result);
					}
					
					//delete CN
					if (!$customerCN->delete()){
						$transaction->rollback();
						$this->result["actionStatus"] =1;
						$this->result["actionMessage"] = $errorMessage;
						$this->result["actionError"] = $customerCN->getErrors();
						$this->returnJSON($this->result);
					}
					//delete header jurnal
					Jurnal::deleteHeaderJurnal($jurnalId,$conn);
					$transaction->commit();
					$this->result["actionStatus"] =0;
					$this->result["actionMessage"] = Yii::t("dialog",$successMessage);
					$this->returnJSON($this->result);
					
				}catch (Exception $e){
					$transaction->rollback();
					$this->result["actionStatus"] =1;
					$this->result["actionMessage"] = $errorMessage;
					$this->result["actionError"] = $e->getMessage();
					$this->returnJSON($this->result);
				}
				
			}
			
			
			$arrObCn = MCustomerCreditNotes::model()->findAll("invoice_id = :id",array(":id"=>$id));
			$arrCn = array();
			foreach($arrObCn as $cn){
				$tmp = array();
				$tmp["id"]= $cn->id;
				$tmp["cn_date"]= $cn->cn_date;
				$tmp["invoice_id"]= $cn->invoice_id;
				$tmp["cn_acc_id"]= $cn->cn_acc_id;
				$tmp["cn_acc_name"]= $cn->cnAcc->acc_code ." - " .$cn->cnAcc->name;
				$tmp["ttl_cn"]= $cn->ttl_cn;
				$tmp["notes"]= $cn->notes;
				$tmp["is_active"]= $cn->is_active;
				$tmp["input_datetime"]= $cn->input_datetime;
				$tmp["user_id"]= $cn->user_id;
				$arrCn[] = $tmp;				
			}			
			//$arrCn = Utils::activeRecord2Array($arrCn);
			$data["arrCn"] = json_encode($arrCn);
			$data["hInv"] = $hInv;
			
			$arrCnCOA=MCoa::model()->findAll("is_active = 1 and acc_code like '4.%' and is_leaf = 1");
			$data["arrCnCOA"] = $arrCnCOA;
			
			$this->layout ="//layouts/ly_blank";
			$this->render('cnForm',$data);
		}
		
		
		public function actionInvoiceDetailForm(){
			$arrItem = MCustomerItem::model()->findAll("is_active = 1");
			
			$acItem = array();
			foreach ($arrItem as $item){
				$tmp = array();
				$tmp["label"] = $item->item_desc;
				$tmp["value"] = $item->item_desc;
				$tmp["id"] = $item->id;
				$tmp["item_price"] = $item->item_price;
				$acItem[] = $tmp;
			}
				
			$data["acItem"]=CJSON::encode($acItem);
				
			$this->layout ="//layouts/ly_blank";
			$this->render('invDetailForm',$data);
		}
		
		public function actionEdit(){
			$strInvDetail = Yii::app()->request->getParam("invDetail","[]");			
			$arrInvDetail = json_decode($strInvDetail);
			$op = Yii::app()->request->getParam("op","");			
			$id = Yii::app()->request->getParam("id","");
			$invoice_no = Yii::app()->request->getParam("invoice_no","");
			$invoice_date = Yii::app()->request->getParam("invoice_date","01-Jan-2000");
			$invoice_date = date_format(date_create_from_format( "d-M-Y", $invoice_date),"Y-m-d");
			$customer_transaction_type_id = Yii::app()->request->getParam("customer_transaction_type_id","");
			$customer_id = Yii::app()->request->getParam("customer_id","");
			$notes = Yii::app()->request->getParam("notes","");
			$payment_type = Yii::app()->request->getParam("payment_type","");
			$userLogin = LoginUser::getUser();
			
			if ($op == "add"){
				$errorMessage = Yii::t("label","Transaksi gagal !");
				$transaction = Yii::app()->db->beginTransaction();
				try{
					$tmp = Jurnal::createHeader("",$invoice_date,"Auto");
					$jurnalId =$tmp["id"];
				
					$hInv = new MCustomerHinvoice();
					$hInv->invoice_no = AutoNumber::getNewCustomerInvoiceNo();
					$hInv->invoice_date =$invoice_date;
					$hInv->ttl_invoice = 0;
					$hInv->ttl_disc = 0;
					$hInv->ttl_paid = 0;
					$hInv->ttl_cn = 0;
					$hInv->payment_type =$payment_type;
					$hInv->jurnal_id= $jurnalId;
					$hInv->input_date_time=date("Y-m-d H:i:s");
					$hInv->user_id =$userLogin ->id;
					$hInv->is_active =1;
					$cek = MCustomerTransactionType::model()->find("id = :custTransTypeId and is_active = 1",array(":custTransTypeId"=>$customer_transaction_type_id));
					if ($cek == null){
						throw new Exception("Invalid Transaction Type");
					}
					$hInv->customer_transaction_type_id = $customer_transaction_type_id;
					$hInv->piutang_acc_id = $cek->piutang_acc_id;
					$customer = MCustomer::model()->find("id =:custId and is_active = 1",array(":custId"=>$customer_id));
					if ($customer == null){
						$errorMessage =Yii::t("label","Customer tidak di kenal..!"); 
						throw new Exception("Invalid Customer");
					}
					$hInv->customer_id = $customer_id;
					$hInv->notes = $notes;				
					if (!$hInv->save()){
						throw new Exception(json_encode($hInv->getErrors()));
					}
					
					//add Detail
					$ttlInv =0;
					$ttlDisc =0;				
					foreach ($arrInvDetail as $invDetail){
						$dInv = new MCustomerDinvoice();
						$dInv->invoice_id = $hInv->id;
						$dInv->customer_item_id = $invDetail->customer_item_id;
						$dInv->notes= $invDetail->notes;
						$dInv->qty = $invDetail->qty;
						$dInv->total = $invDetail->total;
						$dInv->disc = $invDetail->disc;	
	
						$ttlInv += $dInv->total * $dInv->qty;
						$ttlDisc += $dInv->disc;
						
						$item = MCustomerItem::model()->findByPK($invDetail->customer_item_id);
						if ($item == null){
							$errorMessage= Yii::t("label","Item tidak di kenal..");
							throw new Exception("Invalid Customer item");
						}
											
						$dInv->disc_acc_id =$item->disc_acc_id ;
						$dInv->pendapatan_acc_id =$item->pendapatan_acc_id ;						
						//add jurnal
						
						$tmp = Jurnal::createDetail($jurnalId, $hInv->piutang_acc_id, "", "D", ($invDetail->total * $invDetail->qty) - $invDetail->disc);
						$tmp = Jurnal::createDetail($jurnalId, $dInv->disc_acc_id, "", "D", $invDetail->disc);
						$tmp = Jurnal::createDetail($jurnalId, $dInv->pendapatan_acc_id, "", "C", ($invDetail->total * $invDetail->qty));
						
						if (!$dInv->save()){
							throw new Exception(json_encode($dInv->getErrors()));
						}
					} //end foreach detail
					$hInv->ttl_invoice = $ttlInv;
					$hInv->ttl_disc = $ttlDisc;
					if(!$hInv->save()){
						throw new Exception(json_encode($hInv->getErrors()));
					}
				}catch (Exception $e){
					$transaction->rollback();
					$this->pageError($errorMessage,$e->getMessage(),$e);
				}
				$transaction->commit();
				echo"<script type='text/javascript'>alert('".Yii::t("dialog","Data telah di simpan!")."');window.close();</script>";
			}elseif ($op=="edit"){
				
				/*
				 * 1. cek payment status
				 * 2. delete detail jurnal
				 * 3. delete detail invoice
				 * 4. add new detail invoice
				 * 5. add new detail Jurnal
				 * 5. update header invoice (total_inv,total_disc)				 
				 */
					
				$errorMessage = Yii::t("label","Transaksi gagal !");
				$conn = Yii::app()->db;
				$transaction = $conn->beginTransaction();
				try{
					$hInv = MCustomerHinvoice::model()->find("id =:id",array(":id"=>$id));
					if($hInv == null){
						$errorMessage = Yii::t("label","Data Invoice tidak di temukan.");
						throw new Exception("Invalid invoice id");
					} 
					if(($hInv->ttl_paid + $hInv->ttl_cn)  != 0){
						$errorMessage = Yii::t("label","Invoice tidak dapat di rubah karena sudah ada transaksi pembayaran!");
						throw new Exception("Invoice already paid");						
					}
					
					$hInv->invoice_date =$invoice_date;
					$hInv->payment_type =$payment_type;
					$hInv->customer_transaction_type_id =$customer_transaction_type_id;
					$hInv->input_date_time=date("Y-m-d H:i:s");
					$hInv->user_id =$userLogin ->id;
					$hInv->is_active =1;
					$customer = MStudent::model()->find("id =:custId and is_active = 1",array(":custId"=>$customer_id));
					if ($customer == null){
						$errorMessage = Yii::t("label","Customer tidak di kenal..!");
						throw new Exception("Invalid customer");
					}
					$hInv->customer_id = $customer_id;
					$hInv->notes = $notes;
					if (!$hInv->save()){
						throw new Exception(json_encode($hInv->getErrors()));
					}
					$ttlInv = 0;
					$ttlDisc = 0;					
					
					//delete all Detail Jurnal
					Jurnal::deleteDetailJurnal($hInv->jurnal_id,$conn);
					
					//delete all Detail Invoice
					$ssql = "delete from m_customer_dinvoice where invoice_id = :invId";
					$cmd = $conn->createCommand($ssql);
					$cmd->execute(array(":invId"=>$hInv->id));
					
					foreach ($arrInvDetail as $invDetail){
						$dInv = new MCustomerDinvoice();
						$dInv->invoice_id = $hInv->id;
						
						$item = MCustomerItem::model()->findByPK($invDetail->customer_item_id);
						if ($item == null){
							$errorMessage = Yii::t("label","Item tidak di kenal..");
							throw new Exception("Invalid customer item :".$invDetail->customer_item_id);
						}
						
						$dInv->customer_item_id = $invDetail->customer_item_id;
						$dInv->notes= $invDetail->notes;
						$dInv->qty = $invDetail->qty;
						$dInv->total = $invDetail->total;
						$dInv->disc = $invDetail->disc;
						$dInv->disc_acc_id = $item->disc_acc_id;
						$dInv->pendapatan_acc_id = $item->pendapatan_acc_id;
						if(!$dInv->save()){
							throw new Exception(json_encode($dInv->getErrors()));
						}
						
						$ttlInv += $dInv->total * $dInv->qty;
						$ttlDisc += $dInv->disc;												
						$tmp = Jurnal::createDetail($hInv->jurnal_id, $hInv->piutang_acc_id, "", "D", ($invDetail->total * $invDetail->qty) - $invDetail->disc);
						$tmp = Jurnal::createDetail($hInv->jurnal_id, $dInv->disc_acc_id, "", "D",$invDetail->disc);
						$tmp = Jurnal::createDetail($hInv->jurnal_id, $dInv->pendapatan_acc_id, "", "C", ($invDetail->total * $invDetail->qty));
					}
					
					$hInv->ttl_invoice = $ttlInv;
					$hInv->ttl_disc = $ttlDisc;
					if(!$hInv->save()){
						throw new Exception(json_encode($hInv->getErrors()));
					}
				}catch (Exception $e){
					$transaction->rollback();
					$this->pageError($errorMessage,$e->getMessage(),$e);
				}				
				$transaction->commit();
				echo"<script type='text/javascript'>alert('".Yii::t("dialog","Data telah di simpan!")."');window.close();</script>";
							
			}else if($op == "delete"){
				$errorMessage = Yii::t("label","Transaksi gagal !");
				$successMessage = Yii::t("label","Invoice telah dihapus !");
				$id = Yii::app()->request->getParam("id",0);
				$conn = Yii::app()->db;
				$transaction = $conn->beginTransaction();				
				try{
					$hInv = MCustomerHinvoice::model()->findByPK($id);
					if ($hInv == null){
						$errorMessage = Yii::t("label","Invoice tidak di temukan!");
						throw new Exception("Invalid Invoice id");
					}
						
					if(($hInv->ttl_paid + $hInv->ttl_cn) != 0){
						$errorMessage = Yii::t("label","Invoice tidak dapat di hapus karena sudah ada transaksi pembayaran!");
						throw new Exception("Invoice already paid");
					}
					
					
					//delete detail jurnal
					Jurnal::deleteDetailJurnal($hInv->jurnal_id,$conn);
					
					//delete detail invoice
					$ssql = "delete from m_customer_dinvoice where invoice_id = " . $hInv->id;
					$cmd = $conn->createCommand($ssql);
					$cmd->execute();
						
					//delete header invoice & recounting total bulk if exist
					$jurnalId =$hInv->jurnal_id;  
					if(!$hInv->delete()){
						throw new Exception(json_encode($hInv->getErrors()));
					}	
					
					//delate header jurnal
					Jurnal::deleteHeaderJurnal($jurnalId,$conn);
					
					$transaction->commit();
					$this->result["actionStatus"] = 0;
					$this->result["actionMessage"] = $successMessage;
					$this->result["actionError"] ="";
					$this->returnJSON($this->result);
					
				}catch (Exception $e){
					$transaction->rollback();
					$this->result["actionStatus"] = 2;
					$this->result["actionMessage"] = $errorMessage;
					$this->result["actionError"] = $e->getMessage();
					$this->returnJSON($this->result);
				}
				
			}			
		}
		
		public function actionOutstandingDetailList(){
			
			$department_id = Yii::app()->request->getParam("department_id","");
			//$startDate = Yii::app()->request->getParam("start_date","");
			//$startDate = date_format(date_create_from_format( "d-M-Y", Yii::app()->request->getParam("start_date","01-Jan-2000")),"Y-m-d");			
			//$endDate= Yii::app()->request->getParam("end_date","");
			//$endDate = date_format(date_create_from_format( "d-M-Y", Yii::app()->request->getParam("end_date","01-Jan-3000")),"Y-m-d");
			
			$arrCustHInv = MCustomerHinvoice::model()->with(
					array(
						"customer"=>array("alias"=>"a"),
					)
				)->findAll(
					array(
						"condition"=>"(ttl_paid + ttl_cn)  < (ttl_invoice -ttl_disc)",
						"order"=>"t.id desc"
					));

			// rebuilt model
			
			$arrModel = array();
			foreach($arrCustHInv as $custHInv){
				//colNames: ['id','SID','Name','Invoice no','Date','Total','Disc','Paid','Type', 'Keterangan', 'Status','Action'],
				$arrTmp = array();
				$arrTmp["id"] = $custHInv->id;
				$arrTmp["customer_name"] = $custHInv->customer->name;
				$arrTmp["invoice_no"] = $custHInv->invoice_no;
				$arrTmp["invoice_date"] = $custHInv->invoice_date;
				$arrTmp["total_invoice"] = $custHInv->ttl_invoice;
				$arrTmp["disc"] = $custHInv->ttl_disc;
				$arrTmp["total"] = $custHInv->ttl_invoice - $custHInv->ttl_disc;
				$arrTmp["total_paid"] = $custHInv->ttl_paid;
				$arrTmp["total_cn"] = $custHInv->ttl_cn;
				$arrTmp["notes"] = $custHInv->notes;
				$arrTmp["is_active"] = $custHInv->is_active;				
				$arrModel[] = $arrTmp;
			}
			$this->result["actionStatus"] = 0;
			$this->result["model"] = $arrModel;
			$this->returnJSON($this->result);
			
		}
		
		public function actionSettledDetailList(){
			$startDate = Yii::app()->request->getParam("start_date","");
			$startDate = date_format(date_create_from_format( "d-M-Y", Yii::app()->request->getParam("start_date","01-Jan-2000")),"Y-m-d");
			$endDate= Yii::app()->request->getParam("end_date","");
			$endDate = date_format(date_create_from_format( "d-M-Y", Yii::app()->request->getParam("end_date","01-Jan-3000")),"Y-m-d");
			$arrCustomerHInv = MCustomerHinvoice::model()->findAll(
					array(
							"condition"=>"invoice_date >= :startDate and invoice_date <= :endDate and (ttl_invoice - ttl_disc) <= (ttl_paid + ttl_cn) ",
							"params"=>array(":startDate"=>$startDate,":endDate"=>$endDate),
							"order"=>"id desc"
					));
		
			// rebuilt model
			$arrModel = array();
			foreach($arrCustomerHInv as $customerHInv){
				//colNames: ['id','SID','Name','Invoice no','Date','Total','Disc','Paid','Type', 'Keterangan', 'Status','Action'],
				$arrTmp = array();
				$arrTmp["id"] = $customerHInv->id;
				$arrTmp["customer_name"] = $customerHInv->customer->name;
				$arrTmp["invoice_no"] = $customerHInv->invoice_no;
				$arrTmp["invoice_date"] = $customerHInv->invoice_date;
				$arrTmp["total"] = $customerHInv->ttl_invoice - $customerHInv->ttl_disc;
				$arrTmp["paid"] = $customerHInv->ttl_paid;
				$arrTmp["cn"] = $customerHInv->ttl_cn;
				$arrTmp["notes"] = $customerHInv->notes;
				$arrTmp["is_active"] = $customerHInv->is_active;
				$arrModel[] = $arrTmp;
			}
			$this->result["actionStatus"] = 0;
			$this->result["model"] = $arrModel;
			$this->returnJSON($this->result);
				
		}
		
		protected function beforeRender($view){
			if ($this->subMenu != ""){
				$this->title = $this->mainMenu . " - " .$this->subMenu;
			}
			return true;
		}
		
	}
?>